// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html

import { Tools } from "../common/Tools";

const { ccclass, property } = cc._decorator;

const NAME = ["无影白香", "微雨、淡予", "剑指苍穹。", "し淡忘灬", "雾空八戒否", "落花倾城", "荡于旧街", "暴走っ苍穹", "七墓凉"];

const giftMsg = {
    "1": {
        "name": "爱心",
    },
    "2": {
        "name": "荧光棒",
    },
    "3": {
        "name": "棒棒糖",
    },
    "4": {
        "name": "火箭",
    }
}

@ccclass
export default class Gifts extends cc.Component {

    @property({ displayName: "头像库", type: [cc.SpriteFrame] })
    headSprs: Array<cc.SpriteFrame> = [];

    @property(cc.Node)
    head: cc.Node = null;

    @property(cc.Label)
    lbName: cc.Label = null;

    @property(cc.Label)
    lbGift: cc.Label = null;


    // LIFE-CYCLE CALLBACKS:

    // onLoad () {}

    start() {
        // this.randomMsg(giftId);
        this.scheduleOnce(()=>{
            this.node.destroy();
        },3)
    }

    randomMsg(giftId) {
        let name = NAME[Tools.random(0, NAME.length-1)];
        this.lbName.string = name;
        let headSpr = this.headSprs[Tools.random(0, this.headSprs.length-1)];
        this.head.getComponent(cc.Sprite).spriteFrame = headSpr;
        // let giftId=Tools.random(1,4);
        this.lbGift.string=giftMsg[giftId].name;
        this.node.getChildByName("gift"+giftId).active=true;
    }


    // update (dt) {}
    protected onDestroy(): void {
        this.unscheduleAllCallbacks();
    }
}
